package com.woniuxy.pxxt.service.impl;


import com.woniuxy.pxxt.common.result.Result;
import com.woniuxy.pxxt.dao.RoleDao;
import com.woniuxy.pxxt.entity.Role;
import com.woniuxy.pxxt.entity.User;
import com.woniuxy.pxxt.service.RoleService;
import com.woniuxy.pxxt.utils.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 每个账户对应的角色(Role)表服务实现类
 *
 * @author makejava
 * @since 2022-03-07 16:28:53
 */
@Service
public class RoleServiceImpl implements RoleService {

    @Autowired
    private RoleDao roleDao;

    @Autowired
    private RedisTemplate redisTemplate;


    @Override
    public Result findAllRole() {
        List<Role> roleDtoList  = roleDao.findAllRole();
        return Result.ok(roleDtoList);
    }

    @Override
    public  List<Role> findRoleByAccount(User user) {
        List<Role> roles = roleDao.findRoleByAccount(user);
        user.setRoles(roles);
        redisTemplate.opsForValue().set(user.getToken(),user);
        return roles;
    }
}
